/*  

Cafechess Library: Cover basic chess programming needs, like GUI, Engine integration, 
FEN and PGN parsing.

                 \\|//
                 (o o)
--------------ooO-(_)-Ooo----------------------------------
Copyright (C) 2009  By Gregory A. Prentice Snoqualmie, WA
                    www.cafechess.org
                    cafechess@comcast.net
                      Oooo
--------------oooO----(  )---------------------------------
              (  )    (_/
               \_)

Microsoft Public License (Ms-PL)
               
Revisions:

Author        Date    Description:

*/
using System;

namespace Cafechess.Chess.General
{
  /// <summary>
  /// Defines some basic conversion routines.
  /// </summary>
  public class ConvertPiece
  {
   
     /// <summary>
    /// Returns a FEN piece representation base on our 
    /// internal piece enumeration.
    /// </summary>
    /// <param name="piece"></param>
    /// <returns></returns>
    public static Pieces FromFEN(char piece)
    {
      Pieces aPiece=Pieces.None;

      switch(piece)
      {
        case 'K':
          aPiece = Pieces.WhiteKing;
          break;
        case 'Q':
          aPiece = Pieces.WhiteQueen;
          break;
        case 'R':
          aPiece = Pieces.WhiteRook;
          break;
        case 'B':
          aPiece = Pieces.WhiteBishop;
          break;
        case 'N':
          aPiece = Pieces.WhiteKnight;
          break;
        case 'P':
          aPiece = Pieces.WhitePawn;
          break;
        case 'k':
          aPiece = Pieces.BlackKing;
          break;
        case 'q':
          aPiece = Pieces.BlackQueen;
          break;
        case 'r':
          aPiece = Pieces.BlackRook;
          break;
        case 'b':
          aPiece = Pieces.BlackBishop;
          break;
        case 'n':
          aPiece = Pieces.BlackKnight;
          break;
        case 'p':
          aPiece = Pieces.BlackPawn;
          break;
      }    
      return aPiece;
    }  
    /// <summary>
    /// Returns a FEN piece representation base on our 
    /// internal piece enumeration.
    /// </summary>
    /// <param name="piece"></param>
    /// <returns></returns>
    public static char ToFEN(Pieces piece)
    {
      char aPiece=' ';

      switch(piece)
      {
        case Pieces.WhiteKing:
          aPiece = 'K';
          break;
        case Pieces.WhiteQueen:
          aPiece = 'Q';
          break;
        case Pieces.WhiteRook:
          aPiece = 'R';
          break;
        case Pieces.WhiteBishop:
          aPiece = 'B';
          break;
        case Pieces.WhiteKnight:
          aPiece = 'N';
          break;
        case Pieces.WhitePawn:
          aPiece = 'P';
          break;
        case Pieces.BlackKing:
          aPiece = 'k';
          break;
        case Pieces.BlackQueen:
          aPiece = 'q';
          break;
        case Pieces.BlackRook:
          aPiece = 'r';
          break;
        case Pieces.BlackBishop:
          aPiece = 'b';
          break;
        case Pieces.BlackKnight:
          aPiece = 'n';
          break;
        case Pieces.BlackPawn:
          aPiece = 'p';
          break;
      }    
      return aPiece;
    }  
    /// <summary>
    /// Translates an internal piece enumeration into an algebraic piece character.
    /// </summary>
    /// <param name="piece"></param>
    /// <returns>Character representing our piece.</returns>
    public static char ToNotation(Pieces piece)
    {
      char aPiece=' ';
      switch(piece)
      {
        case Pieces.WhiteKing:
        case Pieces.BlackKing:                                 
          aPiece = 'K';
          break;
        case Pieces.WhiteQueen:
        case Pieces.BlackQueen:          
          aPiece = 'Q';
          break;
        case Pieces.WhiteRook:
        case Pieces.BlackRook:
          aPiece = 'R';
          break;
        case Pieces.WhiteBishop:
        case Pieces.BlackBishop:
          aPiece = 'B';
          break;
        case Pieces.WhiteKnight:
        case Pieces.BlackKnight:          
          aPiece = 'N' ;
          break;
        case Pieces.WhitePawn:
        case Pieces.BlackPawn:
          aPiece = 'P';
          break;
      }    
      return aPiece;
    }  
  }
}
